//
//  RAFSUCodeModel.m
//  RAFSUManagement
//
//  Created by Piccolo on 28/03/2018.
//  Copyright © 2018 Rayonics. All rights reserved.
//

#import "RAFSUCodeModel.h"

static const NSInteger defaultQRCodeArrayCount = 7;

@implementation RAFSUCodeModel

- (instancetype)initWithQRCode:(NSString *)QRCode barCode:(NSString *)barCode {
    
    self = [super init];
    if (self) {
        NSArray *QRCodeArray = [QRCode componentsSeparatedByString:@","];
        if (QRCodeArray.count != defaultQRCodeArrayCount) {
            return nil;
        }
        _peripheralName = QRCodeArray[0];
        _macAddress = QRCodeArray[1];
        _IMEIFromQRCode = QRCodeArray[2];
        _IMSI = QRCodeArray[3];
        _operatorTypeString = QRCodeArray[4];
        _province = QRCodeArray[5];
        _city = QRCodeArray[6];
        _IMEIFromBarCode = barCode;
        if ([_IMEIFromBarCode isEqualToString:_IMEIFromQRCode]) {
            _IMEI = _IMEIFromQRCode;
        } else {
            return nil;
        }
    }
    return self;
}

@end
